<template>
  <div class="play">
    <div class="box a"></div>
    <div class="box c"></div>
    <div class="box c"></div>
    <el-card>
      <div class="titel">
        <div class="left">
          <router-link to="/home"> 
            <i class="iconfont icon-shouye-shouye"></i>
          </router-link>
        </div>
        <div class="center">
          <div class="names">{{name}}</div>
         
        </div>
        <div class="right">
          <i class="iconfont icon-sousuo1"></i>
        </div>
      </div>

      <div class="man">
        <img :src="picurl||'https://picsum.photos/760/460?random=1'" alt="">
      </div>
      <div class="textt">
        <Plattext :ztext="text" :times="times" v-if="text.lrc" > </Plattext>
      </div>
       <div class="foo">
        <audio ref="aud" :src="url" controls ></audio>
      </div>

      <div class="footer">
        <div> <i class="iconfont icon-aixin"></i></div>
        <div> <i class="iconfont icon-xiazai"></i></div>
      </div>

     
    </el-card>

  </div>
</template>
<script>
import Plattext from '@/components/playtext.vue'

export default {
   name:'Play',
  data() {
    return{
      url:'',
      lists:[],
      name:'',
      picurl:'',
      text:{},
      times:0
    } 
  },
  components:{
Plattext
  },
  created(){
     this.$store.commit('getids',this.$route.params.id)
     this.$store.commit('result')
    this.getlist()
   this.gettext()
    this.lists=this.$store.state.lists
   this.name=this.lists[0].name
   this.picurl=this.lists[0].picUrl
   

  },
   beforeDestroy(){
  this.removetime()
  },
  mounted(){
   this.gettime()
     
  },
  methods:{
    getlist(){
      this.$http.get('/api/song/url',{params:{id:this.$route.params.id}}).then(res=>{
        // console.log(res.data.data[0]);
        this.url=res.data.data[0].url
       
      })
    },

    gettext(){
      this.$http.get('/api/lyric',{params:{id:this.$route.params.id}}).then(res=>{
        // console.log(res.data,'///');
        this.text=res.data
      })
    },

    // 获取播放音乐时间
     addtime(){
      
          // 播放时长
        // console.log(this.$refs.aud.currentTime);
       this.times=this.$refs.aud.currentTime
        // 总时长
        //  console.log(this.$refs.aud.duration,'//');
        
     },
    gettime(){
        this.$refs.aud.addEventListener("timeupdate",this.addtime)
      
    },
   removetime(){
      this.$refs.aud.removeEventListener("timeupdate",this.addtime)
   }
   
    

    
  }
}
</script>


<style lang="less" scoped>
.play{
.textt{
  overflow: auto;
  width: 360px;
  height: 120px;
  text-align: center;
 position: relative;
 margin-left: 27%;
 color: white;
  margin-top: 370px;
}
.foo{
  margin-top: 30px;
    margin-left: 30%;
}
.titel{
 
  display: flex;
  justify-content: space-between;
  align-items: center;
  
}
.left{
  z-index: 999;
}
.names{
  
  background-color: rgb(142, 190, 140);
 transform: skewX(-30deg);
 letter-spacing: 2px;
 border: 2px solid rgb(39, 18, 228);
 color: red;
  text-align: center;
  width: 260px;
  overflow: hidden;
text-overflow: ellipsis;
white-space:nowrap;/* 不换行 */

}
@keyframes identifier {
  0%{
    transform: rotate(0deg);
  }
 
   100%{
    transform: rotate(36000deg);
  }
}

.man{
  position: absolute;
 
  margin-top: 1px;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  margin-bottom: 20px;
  margin-left: 30%;
  
}
.el-card{
  height: 950px;
  background-color: rgb(54, 54, 54);
}
.man img{
   animation: identifier 3000s linear 2s infinite ;
   margin-top: 30px;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}
.footer{
  
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin-top: 20px;
}

i{
  z-index: 999;
  color: white;
}
.box{
  z-index: 0;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  
}
.a{
   
background: url(../../assets/small.png);
 animation: move 700s linear 0s infinite alternate;
}
.b{
   
  background: url(../../assets/small.png);
   animation: down 270s linear 1s infinite alternate;
}
.c{
 
   background: url(../../assets/big.png);
   animation: down 270s linear 1s infinite alternate;
}
       @keyframes move{/* 创建动画  动画名*/
            0%{
                background-position: 0px 0px  ;/* 背景位置 左右 上下*/
            }
            100%{
                background-position: 15000px 0px  ;/* 背景位置 左右 上下*/
            } 
        }
        @keyframes down{/* 创建动画  动画名*/
            0%{
                background-position: 0px 0px  ;/* 背景位置 左右 上下*/
            }
            100%{
                background-position: 0px -15000px  ;/* 背景位置 左右 上下*/
            }
        }






}


</style>
